package org.example.everyday;

/**
 * <p>
 * Description:TODO 详细描述
 * <p>
 * <p>
 *
 * @author anlu
 * @date 2022/7/17 0017 21:45
 */
public class Lc565 {
    public static void main(String[] args) {
        Lc565 lc565 = new Lc565();
        int[] nums =  {5,4,0,3,1,6,2};
        int res = lc565.arrayNesting(nums);
        System.out.println(res);

    }

    public int arrayNesting(int[] nums) {
        int ans = 0, n = nums.length;
        boolean[] vis = new boolean[n];
        for(int i = 0; i < n; i++){
            int cnt = 0;
            while(!vis[i]){
                vis[i] = true;
                i = nums[i];
                ++cnt;
            }
            ans = Math.max(ans, cnt);
        }
        return ans;
    }
}
